﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;

namespace WebAPIDemo.Controllers
{
    /// <summary>
    /// 路由前缀
    /// </summary>
    [RoutePrefix("api/Teacher")]
    public class TeacherController : ApiController
    {
        [Route("")]
        [HttpGet]
        public int GetAllTeacherCount()
        {
            return 10;
        }

        [Route("QueryTeacherById")]
        [HttpPost]
        public string QueryTeacherById([FromBody] int teacherId)
        {
            return "老师的编号： " + teacherId;
        }

        //路由约束 1
        [Route("GetCount/{age:int=0}")]
        [HttpGet]
        public string GetCount(int age)
        {
            return $"讲师年龄{age}攻击10人";
        }

        //路由约束 2
        [Route("GetTeacherName/{age:int=0}")]
        [HttpPost]
        public string GetTeacherName([FromBody]int Id)
        {
            return $"讲师编号{Id}";
        }
    }
}
